home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / newconf / install.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1993-04-16  |  6.7 KB  |  303 lines

  1. #!/bin/sh
  2. # expects arg1 to be the Postgres home directory
  3. # expects arg2 to be the basename of the Postgres Object directory
  4. # expects arg3 to be the port
  5. # expects arg4 to be the identifier for "SHIP"
  6. # expects arg5 to be the path to 'make'
  7. #
  8. # $Header: /private/postgres/newconf/RCS/install.sh,v 1.40 1992/08/19 08:28:46 mer Exp $
  9.  
  10.  
  11. #
  12. # Now does an installation in $POSTGRESHOME/bin if $POSTGRESHOME is
  13. # defined
  14. #
  15.  
  16. if (test -n "$POSTGRESHOME")
  17. then
  18.     if (test -d "$POSTGRESHOME")
  19.     then
  20.         echo "Installing in $POSTGRESHOME"
  21.         echo
  22.     else
  23.         echo "Error: $POSTGRESHOME does not exist."
  24.         exit 1
  25.     fi
  26.     DEST=$POSTGRESHOME
  27. else
  28.     echo "Installing in $1"
  29.     echo
  30.     DEST=$1
  31. fi
  32.  
  33. TREE=$1
  34. OBJ=$2
  35. PORT=$3
  36. SHIP=$4
  37. MAKE=$5
  38. EXEC_CHOWN=0
  39. EXEC_INITDB=1
  40.  
  41. BINDIR=$DEST/bin
  42. FILEDIR=$DEST/files
  43. SUPODIR=$TREE/`basename $OBJ`/support
  44. SCRIPTDIR=$TREE/src/scripts
  45.  
  46.  
  47. if (test -f $BINDIR/pg_id)
  48. then
  49.     PG_ID=$BINDIR/pg_id
  50. else
  51.     PG_ID=$SUPODIR/pg_id
  52. fi
  53.  
  54.  
  55. if (test $SHIP = 1)
  56. then
  57.     if (test ! -f $PG_ID)
  58.     then
  59.         echo "Executing 'Make pg_id'..."
  60.         $TREE/newconf/Make pg_id 
  61.         if (test ! -f $PG_ID)
  62.         then
  63.             echo "Make pg_id failed - installation aborting."
  64.             exit 1
  65.         fi
  66.     fi
  67.  
  68.     #
  69.     # Test to see if the user is trying to do the install as root.
  70.     # If the user is, we'll have to chown postgres on all the bin, files,
  71.     # and data directories, as well as $POSTGRESHOME itself.
  72.     #
  73.     # If there is no Postgres user (and this will break if there is no 
  74.     # /etc/passwd file), initdb can't be run until the installer fixes this
  75.     # problem.
  76.     #
  77.  
  78.     if (test "`$PG_ID`" = "0")
  79.     then
  80.         if (test "`grep '^postgres' /etc/passwd|sed 's/:.*//'`" = "postgres")
  81.         then
  82.             echo -n "Make install: NOTICE: will change ownership of files"
  83.             echo " to user \"postgres\""
  84.             EXEC_CHOWN=1
  85.         else
  86.             echo "Make install: WARNING: you are installing as root and"
  87.             echo "there is as yet no Postgres user.  Postgres will"
  88.             echo "NOT WORK until you change ownership (see chown(2)) of"
  89.             echo "all files under $TREE and $TREE itself to a registered"
  90.             echo "Postgres user, preferably \"postgres\".  The"
  91.             echo "installation will continue, but the initial template"
  92.             echo "database will not be created."
  93.             echo
  94.             EXEC_INITDB=0
  95.         fi
  96.     fi
  97.  
  98.     if (test ! -f $TREE/newconf/everything.stat)
  99.     then
  100.         echo "Executing 'Make everything'..."
  101.         $TREE/newconf/Make everything 
  102.         if (test $? -ne 0)
  103.         then
  104.             echo "Make everything failed."
  105.             echo "installation aborting."
  106.             exit 1
  107.         fi
  108.     fi
  109. fi
  110.  
  111. if (test ! -d $BINDIR)
  112. then
  113.     echo "creating $BINDIR"
  114.     mkdir $BINDIR
  115. fi
  116.  
  117. SETUIDS="postgres postmaster"
  118. EXECUTABLES="$SETUIDS pg_version monitor pg_id pagedoc shmemdoc"
  119.  
  120. for i in $EXECUTABLES
  121. do
  122.     if (test -f $SUPODIR/$i)
  123.     then
  124.         echo "moving file $SUPODIR/$i"
  125.         mv $SUPODIR/$i $BINDIR
  126.     elif (test -f $BINDIR/$i)
  127.     then
  128.         true
  129.     else
  130.         echo "File $SUPODIR/$i does not exist."
  131.         echo "Your build may have failed"
  132.         echo "or have not been run yet."
  133.         exit 1
  134.     fi
  135. done
  136.  
  137. for i in $SETUIDS
  138. do
  139.     chmod 4755 $BINDIR/$i
  140. done
  141.  
  142. SCRIPTS="createdb createdb.sh destroydb initdb vacuum createuser destroyuser"
  143.  
  144. for i in $SCRIPTS
  145. do
  146.     if (test ! -f $BINDIR/$i)
  147.     then
  148.         echo "moving file $SCRIPTDIR/$i"
  149.         cp $SCRIPTDIR/$i $BINDIR
  150.     fi
  151. done
  152.  
  153. if (test ! -f $BINDIR/ipcclean)
  154. then
  155.     if (test -f $TREE/newconf/IPCCLEAN/ipcclean.$PORT)
  156.     then
  157.         cp $TREE/newconf/IPCCLEAN/ipcclean.$PORT $BINDIR/ipcclean
  158.         echo "creating file $BINDIR/ipcclean"
  159.         chmod 4755 $BINDIR/ipcclean
  160.     else
  161.         echo "File $TREE/newconf/IPCCLEAN/ipcclean.$PORT does not exist."
  162.     fi
  163. fi
  164.  
  165. if (test ! -d $FILEDIR)
  166. then
  167.     echo "creating $FILEDIR"
  168.     mkdir $FILEDIR
  169. fi
  170.  
  171. #
  172. # Now create the bki files
  173. #
  174.  
  175. if (test ! -f $FILEDIR/local1_template1.bki)
  176. then
  177.     if (test ! -f $SUPODIR/local.bki)
  178.     then
  179.         echo "$SUPODIR/local.bki does not exist.  You will need this file"
  180.         echo "to run Postgres properly"
  181.         exit 1
  182.     else
  183.         echo "Moving $SUPODIR/local.bki to $FILEDIR/local1_template1.bki"
  184.         mv $SUPODIR/local.bki $FILEDIR/local1_template1.bki
  185.     fi
  186. fi
  187.  
  188. if (test ! -f $FILEDIR/global1.bki)
  189. then
  190.     if (test ! -f $SUPODIR/dbdb.bki)
  191.     then
  192.         echo "$SUPODIR/dbdb.bki does not exist.  You will need this file"
  193.         echo "to run Postgres properly"
  194.         exit 1
  195.     else
  196.         echo "Moving $SUPODIR/dbdb.bki to $FILEDIR/global1.bki"
  197.         cat $SUPODIR/dbdb.bki | \
  198.             sed -e "s/PGUID/`$SUPODIR/pg_uid`/g" > $FILEDIR/global1.bki
  199.     rm -f $SUPODIR/dbdb.bki
  200.     fi
  201. fi
  202.  
  203. echo "Compiling demo files..."
  204.  
  205. cd $TREE/demo
  206. if (test ! -f makefile)
  207. then
  208.     cat $TREE/newconf/config.mk ./makefile.source > makefile
  209. fi
  210. $MAKE < ./makefile
  211. if (test $? -ne 0)
  212. then
  213.     echo "demo file compilation failed."
  214.     echo "installation aborting."
  215.     exit 1
  216. fi
  217.  
  218. echo "Compiling video demo files..."
  219.  
  220. cd $TREE/video
  221. cp $TREE/demo/*.o $TREE/video
  222. if (test ! -f makefile)
  223. then
  224.     cat $TREE/newconf/config.mk ./makefile.source > makefile
  225. fi
  226. $MAKE < ./makefile
  227. if (test $? -ne 0)
  228. then
  229.     echo "video demo file compilation failed."
  230.     echo "installation aborting."
  231.     exit 1
  232. fi
  233.  
  234. if (test -d $TREE/test/regress)
  235. then
  236.     echo Compiling regression test files...
  237.     cd $TREE/test/regress
  238.     if (test ! -f makefile)
  239.     then
  240.     cat $TREE/newconf/config.mk ./makefile.source > makefile
  241.     chmod 444 makefile
  242.     fi
  243.     $MAKE < ./makefile
  244.     cd funcs
  245.     if (test ! -f makefile)
  246.     then
  247.     cat $TREE/newconf/config.mk ./makefile.source > makefile
  248.     chmod 444 makefile
  249.     fi
  250.     $MAKE < ./makefile
  251. fi
  252.  
  253. echo done
  254. cd $TREE
  255.  
  256. if (test $EXEC_CHOWN -eq 1)
  257. then
  258.     for i in $TREE $TREE/bin $TREE/files $TREE/bin/* $TREE/files/* \
  259.              $TREE/demo $TREE/demo/*
  260.     do
  261.         echo "executing chown to postgres on $i"
  262.         chown postgres $i
  263.         if (test $? -ne 0)
  264.         then
  265.             echo "chown to postgres failed."
  266.             echo "Postgres will NOT work as installed."
  267.             echo "installation aborting."
  268.             exit 1
  269.         fi
  270.     done
  271. fi
  272.  
  273. if (test "$EXEC_INITDB" != 1)
  274. then
  275.     echo "For reasons indicated above, initdb will NOT be executed.  You will"
  276.     echo "have to run it directly after making the above required changes."
  277.     echo "Installation aborting."
  278.     exit 1
  279. fi
  280.  
  281. echo
  282. echo "Initializing template database..." 
  283.  
  284. if (test ! -d data)
  285. then
  286.     $TREE/bin/initdb
  287.     if (test $? -ne 0)
  288.     then
  289.         echo "initialization of template database failed."
  290.         echo "installation aborting."
  291.         exit 1
  292.     fi
  293. fi
  294.  
  295. echo
  296. if [ $DEVELOPMENT = "f" ] 
  297. then
  298.     echo "Cleaning up..."
  299.     rm -f $OBJ/*.o
  300. fi
  301.  
  302. echo "Installation complete."
  303.